//
//  Utiles.m
//  greenbuilding
//
//  Created by lvjian01 on 2017/9/4.
//  Copyright © 2017年 greenbuilding. All rights reserved.
//

#import "Utiles.h"
#import "SDImageCache.h"
#import "UIImageView+AFNetworking.h"
#import "Reachability.h"
#import "AppDelegate.h"

#define PHONE_NUMBER_REGEX @"^1[3578]\\d{9}"

@implementation Utiles

+ (BOOL)checkString:(NSString *)str withRegex:(NSString *)regex{
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
    return [pred evaluateWithObject:str];
}

#pragma 正则匹配手机号
+ (BOOL)checkTelNumber:(NSString *) telNumber
{
//    NSString *pattern = @"^1[3578]\\d{9}";
//    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];
//    BOOL isMatch = [pred evaluateWithObject:telNumber];
//    return isMatch;
    return [self checkString:telNumber withRegex:@"^1[3578]\\d{9}"];
}

+ (BOOL)checkPersonCar:(NSString *)personCar{
    return [self checkString:personCar withRegex:@"/^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/"];
}

+ (BOOL)checkPassword:(NSString *)password{
    //这个不知道为什么这样写，也没有测试该表达式是否成立
    return [self checkString:password withRegex:@"^(?=.*[a-zA-Z0-9].*)(?=.*[a-zA-Z\\W].*)(?=.*[0-9\\W].*).{6,16}$"];
    //这个限制了特殊字符范围
//    return [self checkString:password withRegex:@"^(?![\d]+$)(?![a-zA-Z]+$)(?![!#$%^&*]+$)[\da-zA-Z!#$%^&*]{6,16}$"];
    //这个没有限制特殊字符范围
//    return [self checkString:password withRegex:@"^(?![\d]+$)(?![a-zA-Z]+$)(?![^\da-zA-Z]+$).{6,16}$"];
}

+ (BOOL)validateIDCardNumber:(NSString *)value {
    
    value = [value stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    NSInteger length =0;
    if (!value) {
        return NO;
    }else {
        length = value.length;
        //不满足15位和18位，即身份证错误
        if (length !=15 && length !=18) {
            return NO;
        }
    }
    // 省份代码
    NSArray *areasArray = @[@"11",@"12", @"13",@"14", @"15",@"21", @"22",@"23", @"31",@"32", @"33",@"34", @"35",@"36", @"37",@"41", @"42",@"43", @"44",@"45", @"46",@"50", @"51",@"52", @"53",@"54", @"61",@"62", @"63",@"64", @"65",@"71", @"81",@"82", @"91"];
    
    // 检测省份身份行政区代码
    NSString *valueStart2 = [value substringToIndex:2];
    BOOL areaFlag =NO; //标识省份代码是否正确
    for (NSString *areaCode in areasArray) {
        if ([areaCode isEqualToString:valueStart2]) {
            areaFlag =YES;
            break;
        }
    }
    
    if (!areaFlag) {
        return NO;
    }
    
    NSRegularExpression *regularExpression;
    NSUInteger numberofMatch;
    
    int year =0;
    //分为15位、18位身份证进行校验
    switch (length) {
        case 15:
            //获取年份对应的数字
            year = [value substringWithRange:NSMakeRange(6,2)].intValue +1900;
            
            if (year %4 ==0 || (year %100 ==0 && year %4 ==0)) {
                //创建正则表达式 NSRegularExpressionCaseInsensitive：不区分字母大小写的模式
                regularExpression = [[NSRegularExpression alloc]initWithPattern:@"^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}$"
                                                                        options:NSRegularExpressionCaseInsensitive error:nil];//测试出生日期的合法性
            }else {
                regularExpression = [[NSRegularExpression alloc]initWithPattern:@"^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}$"
                                                                        options:NSRegularExpressionCaseInsensitive error:nil];//测试出生日期的合法性
            }
            //使用正则表达式匹配字符串 NSMatchingReportProgress:找到最长的匹配字符串后调用block回调
            numberofMatch = [regularExpression numberOfMatchesInString:value
                                                               options:NSMatchingReportProgress
                                                                 range:NSMakeRange(0, value.length)];
            
            if(numberofMatch >0) {
                return YES;
            }else {
                return NO;
            }
        case 18:
            year = [value substringWithRange:NSMakeRange(6,4)].intValue;
            if (year %4 ==0 || (year %100 ==0 && year %4 ==0)) {
                regularExpression = [[NSRegularExpression alloc]initWithPattern:@"^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}[0-9Xx]$" options:NSRegularExpressionCaseInsensitive error:nil];//测试出生日期的合法性
            }else {
                regularExpression = [[NSRegularExpression alloc]initWithPattern:@"^[1-9][0-9]{5}19[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}[0-9Xx]$" options:NSRegularExpressionCaseInsensitive error:nil];//测试出生日期的合法性
            }
            numberofMatch = [regularExpression numberOfMatchesInString:value
                                                               options:NSMatchingReportProgress
                                                                 range:NSMakeRange(0, value.length)];
            
            
            if(numberofMatch >0) {
                //1：校验码的计算方法 身份证号码17位数分别乘以不同的系数。从第一位到第十七位的系数分别为：7－9－10－5－8－4－2－1－6－3－7－9－10－5－8－4－2。将这17位数字和系数相乘的结果相加。
                
                int S = [value substringWithRange:NSMakeRange(0,1)].intValue*7 + [value substringWithRange:NSMakeRange(10,1)].intValue *7 + [value substringWithRange:NSMakeRange(1,1)].intValue*9 + [value substringWithRange:NSMakeRange(11,1)].intValue *9 + [value substringWithRange:NSMakeRange(2,1)].intValue*10 + [value substringWithRange:NSMakeRange(12,1)].intValue *10 + [value substringWithRange:NSMakeRange(3,1)].intValue*5 + [value substringWithRange:NSMakeRange(13,1)].intValue *5 + [value substringWithRange:NSMakeRange(4,1)].intValue*8 + [value substringWithRange:NSMakeRange(14,1)].intValue *8 + [value substringWithRange:NSMakeRange(5,1)].intValue*4 + [value substringWithRange:NSMakeRange(15,1)].intValue *4 + [value substringWithRange:NSMakeRange(6,1)].intValue*2 + [value substringWithRange:NSMakeRange(16,1)].intValue *2 + [value substringWithRange:NSMakeRange(7,1)].intValue *1 + [value substringWithRange:NSMakeRange(8,1)].intValue *6 + [value substringWithRange:NSMakeRange(9,1)].intValue *3;
                
                //2：用加出来和除以11，看余数是多少？余数只可能有0－1－2－3－4－5－6－7－8－9－10这11个数字
                int Y = S %11;
                NSString *M =@"F";
                NSString *JYM =@"10X98765432";
                M = [JYM substringWithRange:NSMakeRange(Y,1)];// 3：获取校验位
                
                NSString *lastStr = [value substringWithRange:NSMakeRange(17,1)];
                
                //4：检测ID的校验位
                if ([lastStr isEqualToString:@"x"]) {
                    if ([M isEqualToString:@"X"]) {
                        return YES;
                    }else{
                        
                        return NO;
                    }
                }else{
                    
                    if ([M isEqualToString:[value substringWithRange:NSMakeRange(17,1)]]) {
                        return YES;
                    }else {
                        return NO;
                    }
                    
                }
                
                
            }else {
                return NO;
            }
        default:
            return NO;
    }
}

+(BOOL)isLogin{
//    NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
//    return NO;
//    return [[NSUserDefaults standardUserDefaults] objectIsForcedForKey:UserTokenKEY]?YES:NO;
//    NSLog(@"userToken ==== %@",[[NSUserDefaults standardUserDefaults] objectForKey:UserTokenKEY]);
    return [[NSUserDefaults standardUserDefaults] objectForKey:UserTokenKEY]?YES:NO;
}

+(void)saveUserToken:(NSString *)usertoken{
    [[NSUserDefaults standardUserDefaults] setObject:usertoken forKey:UserTokenKEY];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (void)savePhoneNumber:(NSString *)phoneNumber{
    [[NSUserDefaults standardUserDefaults] setObject:phoneNumber forKey:phoneNumberKey];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (NSString *)phoneNumber{
    if ([[NSUserDefaults standardUserDefaults] objectForKey:phoneNumberKey]) {
        return [[NSUserDefaults standardUserDefaults] objectForKey:phoneNumberKey];
    }
    return @"";
}

+(void)removeUserToken{
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:UserTokenKEY];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+(NSString *)userToken{
//    NSLog(@"userToken===%@",[[NSUserDefaults standardUserDefaults] stringForKey:UserTokenKEY]);

    if ([[NSUserDefaults standardUserDefaults] objectForKey:UserTokenKEY]) {
        return [[NSUserDefaults standardUserDefaults] objectForKey:UserTokenKEY];
    }
        return @"";
}

+(NSString *)deviceId{
//    return [[NSUserDefaults standardUserDefaults] stringForKey:DeviceIdKEY];
    return [[[UIDevice currentDevice] identifierForVendor] UUIDString];
}

+ (void)makeDegbugPath:(BOOL)useDebug{
    [[NSUserDefaults standardUserDefaults] setBool:useDebug forKey:useDebugPath];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (BOOL)isUseDebugPath{
    return [[NSUserDefaults standardUserDefaults] boolForKey:useDebugPath];
}

+(void)chooseImageActionSheetWithCallback:(void(^)(UIActionSheet *sheet))callback{
    static UIActionSheet *sheet = nil;
    static dispatch_once_t responst;
    dispatch_once(&responst, ^{
        sheet = [[UIActionSheet alloc]initWithTitle:nil delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:@"打开照相机" otherButtonTitles:@"从手机相册选择", nil];
    });
    
    callback(sheet);
}

+(NSString *)encodeImageStrWithImage:(UIImage *)image{
//    NSData *imageData = UIImagePNGRepresentation(image);
//    NSData *imageData = UIImageJPEGRepresentation(image, 1);
    
    if (!image) {
        return @"";
    }
    NSData *imageData = [image compressImageToMaxDataSizeKBytes:1*1000];
    
    
    NSLog(@"图片大小：%@",@([imageData length]/1000));
    //    NSData *imageData = UIImageJPEGRepresentation(image, 0.1);
    
    return [imageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
}

//获取当前屏幕显示的viewcontroller

/*
+ (UIViewController *)getCurrentVC
{
    UIViewController *result = nil;
    
//    UIWindow * window = [[UIApplication sharedApplication] keyWindow];
    UIWindow * window = [[UIApplication sharedApplication].delegate window];

    if (window.windowLevel != UIWindowLevelNormal)
    {
        NSArray *windows = [[UIApplication sharedApplication] windows];
        for(UIWindow * tmpWin in windows)
        {
            if (tmpWin.windowLevel == UIWindowLevelNormal)
            {
                window = tmpWin;
                break;
            }
        }
    }
    
    UIView *frontView = [[window subviews] objectAtIndex:0];
    id nextResponder = [frontView nextResponder];
    
    if ([nextResponder isKindOfClass:[UIViewController class]])
        result = nextResponder;
    else
        result = window.rootViewController;
    
    return result;
}
 
*/
+(UIViewController *)getCurrentVC
{
    UIViewController *result = nil;
//    UIWindow * window = [[UIApplication sharedApplication] keyWindow];
    UIWindow * window = [[UIApplication sharedApplication].delegate window];

    //app默认windowLevel是UIWindowLevelNormal，如果不是，找到UIWindowLevelNormal的
    if (window.windowLevel != UIWindowLevelNormal)
    {
        NSArray *windows = [[UIApplication sharedApplication] windows];
        for(UIWindow * tmpWin in windows)
        {
            if (tmpWin.windowLevel == UIWindowLevelNormal)
            {
                window = tmpWin;
                break;
            }
        }
    }
    id  nextResponder = nil;
    UIViewController *appRootVC=window.rootViewController;
    //    如果是present上来的appRootVC.presentedViewController 不为nil
    if (appRootVC.presentedViewController) {
        nextResponder = appRootVC.presentedViewController;
    }else{
        
        NSLog(@"===%@",[window subviews]);
        UIView *frontView = [[window subviews] objectAtIndex:0];
        nextResponder = [frontView nextResponder];
    }
    
    if ([nextResponder isKindOfClass:[UITabBarController class]]){
        UITabBarController * tabbar = (UITabBarController *)nextResponder;
        UINavigationController * nav = (UINavigationController *)tabbar.viewControllers[tabbar.selectedIndex];
        //        UINavigationController * nav = tabbar.selectedViewController ; 上下两种写法都行
        result=nav.childViewControllers.lastObject;
        
    }else if ([nextResponder isKindOfClass:[UINavigationController class]]){
        UIViewController * nav = (UIViewController *)nextResponder;
        result = nav.childViewControllers.lastObject;
    }else{
        result = nextResponder;
    }
    return result;
}

/*这个方法有问题，暂时没解决
- (UIViewController *)getCurrentVC

{
    
    UIViewController *appRootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
    
    UIViewController *topVC = appRootVC;
    
    if (topVC.presentedViewController) {
        
        topVC = topVC.presentedViewController;
        
    }
    
    return topVC;
    
}
*/


// 获取当前屏幕中present出来的viewcontroller
+ (UIViewController *)getPresentedViewController
{
    UIViewController *appRootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
    UIViewController *topVC = appRootVC;
    if (topVC.presentedViewController) {
        topVC = topVC.presentedViewController;
    }
    
    return topVC;
}

+(NSString *)urlstrWithPath:(NSString *)path detailId:(NSNumber *)detailId{
    NSDictionary *param1 = @{@"id":detailId};
    NSString *urlstr = [NSString stringWithFormat:@"%@?appId=%@&params=%@&userToken=%@",path,AppID,[param1 mj_JSONString],[Utiles userToken]];
    
    NSCharacterSet *encodeUrlSet = [NSCharacterSet URLQueryAllowedCharacterSet];
    
    NSString *encodeUrl = [dlpath(urlstr) stringByAddingPercentEncodingWithAllowedCharacters:encodeUrlSet];
    return encodeUrl;

}

+(NSString *)urlstrWithpath:(NSString *)path params:(NSString *)params{
    
    if ([path containsString:@"?"]) {
        return dlpath(path);
    }
    NSString *urlstr = [NSString stringWithFormat:@"%@?appId=%@&params=%@&userToken=%@",path,AppID,params,[Utiles userToken]];
    NSCharacterSet *encodeUrlSet = [NSCharacterSet URLQueryAllowedCharacterSet];
    
    NSString *encodeUrl = [dlpath(urlstr) stringByAddingPercentEncodingWithAllowedCharacters:encodeUrlSet];
    return encodeUrl;

}

+(NSString *)urlstrWithpath:(NSString *)path paramsDic:(NSDictionary *)params{
    NSString *urlstr = [NSString stringWithFormat:@"%@?appId=%@&params=%@&userToken=%@",path,AppID,[params mj_JSONString],[Utiles userToken]];
    
    NSCharacterSet *encodeUrlSet = [NSCharacterSet URLQueryAllowedCharacterSet];
    
    NSString *encodeUrl = [dlpath(urlstr) stringByAddingPercentEncodingWithAllowedCharacters:encodeUrlSet];
    return encodeUrl;
}

+ (NSArray *)collectionTypes{
    if ([[NSUserDefaults standardUserDefaults] objectForKey:@"collectionTypes"]) {
        return [[NSUserDefaults standardUserDefaults] objectForKey:@"collectionTypes"];
    }
    return nil;
}

+ (void)setCollecTionTypes:(NSArray *)collectionTypes{
    [[NSUserDefaults standardUserDefaults] setObject:collectionTypes forKey:@"collectionTypes"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}


+(void)showSimpleAlertWithMessage:(NSString *)message{
    static UILabel *alert = nil;
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^{
//        CGRect frame = [[UIScreen mainScreen]bounds];
//        alert = [[UILabel alloc]initWithFrame:CGRectMake(Main_Screen_Width/2-60, Main_Screen_Height - 50, 120, 30)];
        alert = [[UILabel alloc] init];
//        alert.center = CGPointMake(Main_Screen_Width / 2, Main_Screen_Height - 70);
        alert.backgroundColor = [UIColor colorWithWhite:0 alpha:.5];
//        [alert sizeToFit];
        alert.numberOfLines = 0;
        alert.layoutMargins = UIEdgeInsetsMake(5, 10, 5, 10);
        alert.font = [UIFont systemFontOfSize:13.0f];
        alert.textColor = [UIColor whiteColor];
        [alert setTextAlignment:NSTextAlignmentCenter];
//        alert.layer.cornerRadius = 15.0f;
        alert.layer.masksToBounds = YES;
        
    });
    
    [alert setText:message];
    [alert sizeToFit];
//    RECT_CHANGE_width(alert, WIDTH(alert) + 20);
    alert.width += 30;
    alert.center = CGPointMake(Main_Screen_Width / 2, Main_Screen_Height/2-150);

//    alert.center = CGPointMake(Main_Screen_Width / 2, Main_Screen_Height - 70);

    alert.layer.cornerRadius = HEIGHT(alert) / 2;
    

    [alert setAlpha:1.0f];
    
    [[UIApplication sharedApplication].keyWindow addSubview:alert];
    
    
    [UIView animateWithDuration:0.5f delay:1.0f options:UIViewAnimationOptionAllowAnimatedContent animations:^{
        alert.alpha = 0.0f;
    } completion:^(BOOL finished) {
        [alert removeFromSuperview];
    }];
    
}

 /*
+ (void)showAlertWithMessage:(NSString *)message{
    static UIAlertView *alert;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        alert = [[UIAlertView alloc] initWithTitle:nil message:message delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    });
    
    alert.message = message;
    
    [alert show];
}
 
 */

/*
+ (void)showSimpleAlertWithMessage:(NSString *)message{
    static UIAlertView *alert;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        alert = [[UIAlertView alloc] initWithTitle:nil message:message delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    });
    
    alert.message = message;
    
    [alert show];

}
 
 */

// 获取Caches目录路径
+ (NSString *)getCachesPath{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask,YES);
    NSString *cachesDir = [paths lastObject];
    return cachesDir;
}

+ (CGFloat)folderSizeAtPath:(NSString *)path{
    NSFileManager *manager = [NSFileManager defaultManager];
    CGFloat size = 0;
    if ([manager fileExistsAtPath:path]) {
        // 目录下的文件计算大小
        NSArray *childrenFile = [manager subpathsAtPath:path];
        for (NSString *fileName in childrenFile) {
            NSString *absolutePath = [path stringByAppendingPathComponent:fileName];
            size += [manager attributesOfItemAtPath:absolutePath error:nil].fileSize;
        }
        //SDWebImage的缓存计算
        size += [[SDImageCache sharedImageCache] getSize]/1024.0/1024.0;
        // 将大小转化为M
        return size / 1024.0 / 1024.0;
        
//        return [[manager attributesOfItemAtPath:path error:nil] fileSize];
    }
    return 0;
}

+ (void)cleanCaches:(NSString *)path{
    NSFileManager *fileManager = [NSFileManager defaultManager];
    if ([fileManager fileExistsAtPath:path]) {
        NSArray *childrenFiles = [fileManager subpathsAtPath:path];
        for (NSString *fileName in childrenFiles) {
            // 拼接路径
            NSString *absolutePath = [path stringByAppendingPathComponent:fileName];
            // 将文件删除
            [fileManager removeItemAtPath:absolutePath error:nil];
        }
    }
    //SDWebImage的清除功能
    [[SDImageCache sharedImageCache] clearDiskOnCompletion:nil];
    [[SDImageCache sharedImageCache] clearMemory];
}

+ (CGFloat)cacheSize{
    return [self folderSizeAtPath:NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject] + [self folderSizeAtPath:NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES).lastObject] + [self folderSizeAtPath:NSTemporaryDirectory()];
}

/* 自定义的方法, 实际使用时的传入参数以自己需求为准 */
+ (void)addLayerWith:(UIView *)view {
    /* 初始化一个layer */
    CAShapeLayer *border = [CAShapeLayer layer];
    /* 虚线的颜色 */
    border.strokeColor = [UIColor gb_textColor_4D4D4D].CGColor;
    /* 填充虚线内的颜色 */
    border.fillColor = nil;
    /* 贝塞尔曲线路径 */
    border.path = [UIBezierPath bezierPathWithRect:view.bounds].CGPath;
    /* 虚线宽度 */
    border.lineWidth = 1.0f;
    //border.frame = view.bounds; /* 这个因为给了路径, 而且用的约束给的控件尺寸, 所以没什么效果 */
    /* 官方API注释:The cap style used when stroking the path. Options are `butt', `round'
     * and `square'. Defaults to `butt'. */
    /* 意思是沿路径画帽时的样式 有三种 屁股 ; 圆; 广场 ,我没感觉有啥区别 可以自己试一下*/
    border.lineCap = @"square";
    /* 虚线的每个点长  和 两个点之间的空隙 */
    border.lineDashPattern = @[@3, @2];
    /* 添加到你的控件上 */
    [view.layer addSublayer:border];
}

+ (void)seeLargeUrlImage:(NSString *)imageUrl{
    static UIImageView *imageView;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        imageView= [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        imageView.backgroundColor = [UIColor colorWithWhite:0 alpha:.6];
        imageView.userInteractionEnabled = YES;
        imageView.contentMode = UIViewContentModeScaleAspectFit;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:imageView action:@selector(removeFromSuperview)];
        [imageView addGestureRecognizer:tap];
    });
    [imageView setImageWithURL:[NSURL URLWithString:dlpath(imageUrl)]];
    [[UIApplication sharedApplication].keyWindow addSubview:imageView];
}

+ (BOOL)isNewWorkOK{
        
//    AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
//    NSLog(@"%@",@(manager.networkReachabilityStatus));
//    if (manager.networkReachabilityStatus == AFNetworkReachabilityStatusUnknown || manager.networkReachabilityStatus == AFNetworkReachabilityStatusNotReachable) {
//        return NO;
//    }
//    return YES;
    
    AppDelegate *appDlg = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    return appDlg.isReachable;
}

+ (void)saveAliOrder:(NSString *)aliOrder{
    [[NSUserDefaults standardUserDefaults] setObject:aliOrder forKey:aliOrderKey];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (NSString *)aliOrder{
    if ([[NSUserDefaults standardUserDefaults] objectForKey:aliOrderKey]) {
        return [[NSUserDefaults standardUserDefaults] objectForKey:aliOrderKey];
    }
    return @"";
}

+ (BOOL)isAliOrder{
    return [[NSUserDefaults standardUserDefaults] objectForKey:aliOrderKey]?YES:NO;
}

+ (void)removeAliOrder{
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:aliOrderKey];
    [[NSUserDefaults standardUserDefaults] synchronize];
}



@end
